﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MvcViewPage.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	PortfoliosBasic
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <link href="../../Content/Portfolios/PortfoliosBasic.css" rel="stylesheet" type="text/css" />
    <h2>PortfoliosBasic</h2>

    <script src="../../Scripts/jquery-1.3.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        var row_max = 7;
        var row_sort = 1;
        var sort_desc = false;
        //Load form
        $(document).ready(function(){
            //Load Drop down Stock
            $.getJSON("/Portfolios/GetAllStock", null, function(data) {  
                for(var i in data)              
                    $("<option value='" + data[i].Value + "'>" + data[i].Text + "</option>").appendTo("#DropStock");             
                $('#DropStock').change();
            });
            
            //Load Drop down Port
            $.getJSON("/Portfolios/GetAllPort", null, function(data) {  
                for(var i in data)
                    $("<option value='" + data[i].Value + "'>" + data[i].Text + "</option>").appendTo("#DropPort");             
                $('#DropPort').change();
            });
        });
        
        function UpdateMaxPage(port)
        {
            
        }
        
        function DropPortChange(key) { 
            //lay port_id
            var port_id = $('#DropPort').val();
        
            //update lai Cashinfo
            $.getJSON("/Portfolios/GetPortInfo", { port_id: port_id}, function(data) {                
                $("#CashName").text(data.CashName);
                $("#AmountMoney").text(data.AmountMoney);
            });
            
            //update lai page_max
            $.getJSON("/Portfolios/GetMaxPage_PortBasic", {port_id: port_id , row_max:row_max}, function(data){                 
                $("#page_max").text(data);
            });
                    
            //key : neu key = 0 ==> page = 1 **** key = num ==> page = page + key
            var page;         
            switch(key)
            {
                case 0: page = 1; break;
                case 1: page = parseInt($("#page_current").text()); break;
                case 2: page = parseInt($("#page_current").text()) - 1; break;
                case 3: page = parseInt($("#page_current").text()) + 1; break;
            } 
            
            if(page > $("#page_max").text())
                page = $("#page_max").text();
            if(page < 1)
                page = 1;
             
            //update lai page
            $("#page_current").text(page);
        
            $.getJSON("/Portfolios/GetPortBasic", {port_id: port_id, row_max:row_max, page:page, row_sort:row_sort,sort_desc:sort_desc}, function(data){                 
            
                //ghi du lieu moi
                for(var i in data)   
                {               
                    if(i > row_max)
                        break;  
                    $("#row" + i.toString() + "col1").text(data[i].CompanyName);
                    $("#row" + i.toString() + "col2").text(data[i].StockSymbol);
                    $("#row" + i.toString() + "col3").text(data[i].Price);
                    $("#row" + i.toString() + "col4").text(data[i].Amount);
                    $("#row" + i.toString() + "col5").text(data[i].Total);
                    i++;
                }

                //xoa nhung row ko co du lieu
                for(i; i< row_max; i++)
                {
                    $("#row" + i.toString() + "col1").text("");
                    $("#row" + i.toString() + "col2").text("");
                    $("#row" + i.toString() + "col3").text("");
                    $("#row" + i.toString() + "col4").text("");
                    $("#row" + i.toString() + "col5").text("");
                }
            });
        }
            
        function DropStockChange() {
            $.getJSON("/Portfolios/GetStockInfo", { stock_id: $('#DropStock').val()}, function(data) {                
                $("#CompanyName").text(data.CompanyName);
                $("#Price").text(data.Price);
                $("#TypeSTC").text(data.TypeSTC);
            });
        }
        
        function SortChange(i)
        {
        
            if(i == row_sort)
                sort_desc = !sort_desc;
            else
            {   
                row_sort = i;
                sort_desc = false;
            }
            DropPortChange(1);
        }
        
        function AddBasic()
        {
            $.getJSON("/Portfolios/AddBasicStockTransaction", { port_id:$('#DropPort').val() , stock_id:$('#DropStock').val() , soluong:$('#TB_soluong').val() , gia:$('#TB_gia').val() , phigiaodich:$('#TB_phigiaodich').val() }, function(data) {                
                if(data.result == true)
                    DropPortChange(1);
                alert(data.message);
            });
        }
    </script>
    <div class="Content_1">
        <div class="Dropdown">
            Tên danh mục&nbsp;&nbsp;
            <select id="DropPort" onchange="DropPortChange(0);"></select>
        </div>
        <div class="Content_1_tab">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Tài khoản tiền mặt : 
            <span id="CashName" class="Content_1_tab_normal">123</span>
        </div>
        <div class="Content_1_tab">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Số dư tiền mặt : 
            <span id="AmountMoney" class="Content_1_tab_normal">123</span>
        </div>
    </div>
    <div class="Title">
        <%=Html.ActionLink("Basic - Gidview Show", "PortfoliosBasic") %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <%=Html.ActionLink("Edit  - Gidview Full", "PortfoliosEdit") %>
    </div>
<% 
    //Tham so can thiet
    int row_max = 7;
        
    //Draw header gridview
    Response.Write("<div class='GridView_Header'>");
    Response.Write("<span class='GridView_Coulumn_1' onclick='SortChange(1);'>Công ty</span>");
    Response.Write("<span class='GridView_Coulumn_2' onclick='SortChange(2);'>Chứng khoán</span>");
    Response.Write("<span class='GridView_Coulumn_3' onclick='SortChange(3);'>Giá</span>");
    Response.Write("<span class='GridView_Coulumn_4' onclick='SortChange(4);'>Số lượng</span>");
    Response.Write("<span class='GridView_Coulumn_5' onclick='SortChange(5);'>Giá trị</span> ");
    Response.Write("</div>");
    
    //Draw empty row
    for (int i = 0; i < row_max; i++)
    {
        if (i % 2 == 0)
            Response.Write("<div class='GridView_ItemRow'>");
        else
            Response.Write("<div class='GridView_AlterRow'>");

        Response.Write("<span id='row" + i.ToString() + "col1' class='GridView_Coulumn_1'></span>");
        Response.Write("<span id='row" + i.ToString() + "col2' class='GridView_Coulumn_2'></span>");
        Response.Write("<span id='row" + i.ToString() + "col3' class='GridView_Coulumn_3'></span>");
        Response.Write("<span id='row" + i.ToString() + "col4' class='GridView_Coulumn_4'></span>");
        Response.Write("<span id='row" + i.ToString() + "col5' class='GridView_Coulumn_5'></span>");

        Response.Write("</div>");
    }
    
    //Draw footer
    Response.Write("<div class='GridView_Footer'>");
    Response.Write("Đơn vị : ngàn VNĐ.");
    Response.Write("</div>");
    
    //Draw Page
    Response.Write("<div class='GridView_Page'>");
    Response.Write("<input type='button' value='<' onclick='DropPortChange(2);'></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
    Response.Write("<span id='page_current'></span>&nbsp;/&nbsp;");
    Response.Write("<span id='page_max'></span>");
    Response.Write("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='button' value='>' onclick='DropPortChange(3);'></span>");
    Response.Write("</div>");
%>

    <div class="Title">
        Thêm giao dich
    </div>
    <div class="Content_2">
        <div class="FormAdd_Label">
            Cổ phiếu
        </div>
        <div class="Dropdown">
            <select id="DropStock" onchange="DropStockChange();"></select>
        </div>
        <div class="Content_2_tab1">
            |
        </div>
        <div class="Content_2_tab2">
            <span id="CompanyName"></span>
        </div>
        <div class="Content_2_tab1">
            |
        </div>
        <div class="Content_2_tab2">
            <span id="Price"></span>
        </div>
         <div class="Content_2_tab1">
            |
        </div>
        <div class="Content_2_tab2">
            <span id="TypeSTC"></span>
        </div>
    </div>
    
    <div class="Content_2">
        <div class="FormAdd_Label">
            Số lượng
        </div>
        <div class="FormAdd_Data">
            <input id="TB_soluong" type="text" />
        </div>
        <div class="FormAdd_Label">
            Giá
        </div>
        <div class="FormAdd_Data">
            <input id="TB_gia" type="text" />Đơn vị : ngàn VNĐ.
        </div>
        <div class="FormAdd_Label">
            Phí giao dịch
        </div>
        <div class="FormAdd_Data">
            <input id="TB_phigiaodich" type="text" />
        </div>
        <div class="FormAdd_Label">
            <input type="button" value="Lưu thay đổi" onclick="AddBasic();"/>
        </div>
    </div>
</asp:Content>

